/**
 * @(#)jPPP.java
 *
 *
 * @author
 * @version 1.00 2008/7/15
 */
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class jPPP extends JFrame implements ActionListener{
    JTextField sequenceKeyf;
    JComboBox lengthf;
    JTextField cardNumf;
    JTextArea card;
    JFrame frame;
    /**
     * Creates a new instance of <code>jPPP</code>.
     */
    public jPPP() {
    	setTitle("jPPP");
        setDefaultLookAndFeelDecorated(true);
        setLayout(new BorderLayout());
        try{
         UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }catch(Exception e){ }

        JPanel sequenceKey = new JPanel(new FlowLayout());
        sequenceKeyf = new JTextField(64);
        JLabel sequenceKeyl = new JLabel("Sequence Key: ");
        sequenceKey.add("West",sequenceKeyl);
        sequenceKey.add("Center",sequenceKeyf);

        JPanel length = new JPanel(new BorderLayout());
        lengthf = new JComboBox(new String[]{"4","5","6","7","8"});
        JLabel lengthl = new JLabel("Passcode Length: ");
        length.add("West",lengthl);
        length.add("Center",lengthf);

        JPanel cardNum = new JPanel(new BorderLayout());
        cardNumf = new JTextField(3);
        cardNumf.setText("1");
        JLabel cardNuml = new JLabel("Card #: ");
        cardNum.add("West",cardNuml);
        cardNum.add("Center",cardNumf);

        card = new JTextArea();
        card.setEditable(false);
        card.setBackground(this.getBackground());

        JButton calculate = new JButton("Display");
        calculate.addActionListener(this);
        getRootPane().setDefaultButton(calculate);

    	JPanel p = new JPanel(new FlowLayout());
    	p.add(cardNum);
        p.add(length);
        p.add(calculate);

        add("North",sequenceKey);
        add("Center",p);
        add("South",card);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        pack();
		setVisible(true);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
    	jPPP mine = new jPPP();

    }
    public void actionPerformed(ActionEvent e) {
    	if(lengthf.getSelectedItem().equals("") || cardNumf.getText().equals("")){
    		JOptionPane.showMessageDialog(this,"Missing input","Error",JOptionPane.ERROR_MESSAGE);
    	}else{
    		String sequenceKeyV = sequenceKeyf.getText();
    		int lengthV = Integer.parseInt(lengthf.getSelectedItem().toString());
    		int cardNumV = Integer.parseInt(cardNumf.getText());
    		try{
    			PPPengine.setPasscodeLength(lengthV);
        		PPPengine go = new PPPengine(sequenceKeyV);
        		card.setText(go.generatePasscodeCard(cardNumV,false));
    		}catch(Exception ex){
    			JOptionPane.showMessageDialog(this,"Invalid Input: "+ex.getMessage(),"Error",JOptionPane.ERROR_MESSAGE);
    		}
        	pack();
    	}
	}


}
